package kr.saeildamil.androidstudy_second23;

import kr.saeildamil.androidstudy_second.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.ViewSwitcher.ViewFactory;

public class TextSwitcherTest extends Activity {
	TextSwitcher mSwitcher;
	int mAdIdx;
	String[] arAd;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_textswitcher);
		
		arAd=getResources().getStringArray(R.array.textswitchertest_arAD);
		mSwitcher=(TextSwitcher) findViewById(R.id.ch23_textswitcher);
		mSwitcher.setFactory(mFactory);

		mSwitcher.setText(arAd[mAdIdx]);
	}
	public void mOnClick(View v){
		switch (v.getId()) {
		case R.id.ch23_textswitcher_btn:
			mAdIdx=mAdIdx==arAd.length-1?0:mAdIdx+1;
			mSwitcher.setText(arAd[mAdIdx]);
			break;
		}
	}
	ViewSwitcher.ViewFactory mFactory=new ViewFactory() {
		
		@Override
		public View makeView() {
			TextView text=new TextView(TextSwitcherTest.this);
			text.setTextSize(22);
			text.setBackgroundColor(Color.YELLOW);
			text.setTextColor(Color.BLACK);
			return text;
		}
	};
	
}
